<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <!-- 
        promise的方法
     -->
     <script>
        // 1、Promise实例化，需要传入一个executor函数，为参数，否则会报错。
        // let p = new Promise((resolve, reject) => reject())
        // // Promie.resolve
        // let p1 = Promise.resolve(1)
        // let p2 = p1.then()
        // console.log(p2);
        // // Promise.prototype.finally
        // // 如果一直处于pending状态则finally不会执行
        // let p3 = new Promise((resolve, reject) => {
            
        // })
        // p3.then(() => {
        //     console.log('then执行');
        // }).finally(() => {
        //     console.log('finally执行');
        // })
        // Promise.all
        // let p4 = new Promise(() => {})
        // let p5 = Promise.resolve()
        // let p6 = Promise.reject()
        // let p7 = Promise.resolve(7)
        // let pall1 = Promise.all([p4, p5])
        // console.log(pall1);
        // let pall2 = Promise.all([p4, p5, p6])
        // console.log(pall2);
        // let pall3 = Promise.all([p5, p7])
        // pall3.then(vals => {
        //     console.log(vals);
        // })

        // let p8 = new Promise((resolve, reject) => {
        //     resolve(new Promise((res, rej) => {rej(10)}))
        // }).then(res => {
        //     console.log(res);
        // })
        let p9 = new Promise((resolve, reject) => {
            resolve({
                then(res, rej) {
                    console.log(66)
                    rej(999)
                }
            })
            // reject(Promise.resolve())
        })
        p9.then(res => {
            console.log(res, 'resolved');
        }).catch(err => {
            console.log(err, 'rejected');
        })
        console.log(p9);
     </script>
</body>
</html>